using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Text.RegularExpressions;
namespace KbWorksBlogMigrationtool
{
    static class Util
    {
        static public string RemoveTags(string OldText)
        {//&lt;/li&gt;
            while (OldText.Contains("&lt;/li&gt;"))
            {
                Regex regexText = new Regex("&lt;ul&gt;");
              //  string test;
                OldText = regexText.Replace(OldText, "");
                Regex RegText2 = new Regex("&lt;li&gt;");
                OldText = RegText2.Replace(OldText, "");
                Regex RegText3 = new Regex("&lt;/li&gt;");
                OldText = RegText3.Replace(OldText, "");
                
            Regex RegText4 = new Regex("&lt;/ul&gt;");
                OldText = RegText4.Replace(OldText, "");
                //Regex regtext5 =new Regex("_x0020_");
                //OldText = regtext5.Replace(OldText, " ");
                //Regex regtext6 = new Regex("_x0028_");
                //OldText = regtext6.Replace(OldText, "(");
                //Regex regtext7 = new Regex("_x0");
                //OldText = regtext7.Replace(OldText, ")");
            }
            Regex regtext5 = new Regex("_x0020_");
            OldText = regtext5.Replace(OldText, " ");
            Regex regtext6 = new Regex("_x0028_");
            OldText = regtext6.Replace(OldText, "(");
            Regex regtext7 = new Regex("_x0");
            OldText = regtext7.Replace(OldText, ")");
            return OldText;
        }
        static public XmlNodeList RunXPathQuery(XmlNode XmlNodeToQuery, string XPathQuery)
        {
            // load the complete XML node and all its child nodes into a XML document
            XmlDocument Document = new XmlDocument();
            Document.LoadXml(XmlNodeToQuery.OuterXml);

            // all the possible namespaces used by SharePoint and a randomly choosen prefix
            const string SharePointNamespacePrefix = "sp";
            const string SharePointNamespaceURI =
                "http://schemas.microsoft.com/sharepoint/soap/";

            const string ListItemsNamespacePrefix = "z";
            const string ListItemsNamespaceURI = "#RowsetSchema";

            const string PictureLibrariesNamespacePrefix = "y";
            const string PictureLibrariesNamespaceURI =
                "http://schemas.microsoft.com/sharepoint/soap/ois/";

            const string WebPartsNamespacePrefix = "w";
            const string WebPartsNamespaceURI =
                "http://schemas.microsoft.com/WebPart/v2";

            const string DirectoryNamespacePrefix = "d";
            const string DirectoryNamespaceURI =
                "http://schemas.microsoft.com/sharepoint/soap/directory/";

            // now associate with the xmlns namespaces (part of all XML nodes returned
            // from SharePoint) a namespace prefix which we can then use in the queries
            XmlNamespaceManager NamespaceMngr = new XmlNamespaceManager(Document.NameTable);

            NamespaceMngr.AddNamespace(SharePointNamespacePrefix, SharePointNamespaceURI);
            NamespaceMngr.AddNamespace(ListItemsNamespacePrefix, ListItemsNamespaceURI);
            NamespaceMngr.AddNamespace(PictureLibrariesNamespacePrefix, PictureLibrariesNamespaceURI);
            NamespaceMngr.AddNamespace(WebPartsNamespacePrefix, WebPartsNamespaceURI);
            NamespaceMngr.AddNamespace(DirectoryNamespacePrefix, DirectoryNamespaceURI);

            // run the XPath query and return the result nodes
            return Document.SelectNodes(XPathQuery, NamespaceMngr);
        }
    }
}
